<?php

namespace app\http\middleware;

use think\facade\Cache;
use app\facade\Redis;

class Safety
{
    use \traits\controller\Jump;

    public function handle($request, \Closure $next)
    {
        $ip = $request->ip();
        $url = $request->baseUrl();
        // $safety = config('auth.frequent');
        // $quantity = isset($safety[$url]) ? $safety[$url] : 1000;
        $limit = config('auth.limit');
        if (in_array($ip, $limit)) {
            $this->result(null, 404, language('base.error'));
        }
        // $url = strtolower($url);
        // if (in_array($url, $safety) && $request->isPost()) {
        //     $unique = date('YmdHi') . '_' . $url . '_' . $ip;
        //     if (Redis::get($unique)) {
        //         $this->result(null, 404, language('base.frequent'));
        //     } else {
        //         Redis::setex($unique, 2, 1);
        //     }
        // }
        return $next($request);
    }
}
